<?
  include('../../../config/cfg.php');
  $debug=true;
  //get parameters
  $mac=$_GET["mac"];
  //extract firmware from mac 
  $qry="SELECT c.`extension`, pt.`registrar`, pf.`id`, pf.`name` ";
  $qry.="FROM `cw_prov_client` AS pc ";
  $qry.="JOIN `cw_prov_template` AS pt ON pt.`id`=pc.`id_template` ";
  $qry.="JOIN `cw_prov_firmware` AS pf ON pf.`id`=pt.`firmware` ";
  $qry.="JOIN `cw_client` AS c ON c.`id`=pc.`id_client` ";
  $qry.="WHERE pc.`mac` LIKE '".$mac."'";
  $res=$db->Execute($qry);
  if($res!==false){
    if($arr=$res->FetchRow()){
    	$extension=$arr["extension"];
      $firmware="firmware_".$arr["id"].".bin";
      echo "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">\n";
      echo "<HTML>\n";
      echo "<pre>\n";
      echo "firmware: http://".$arr["registrar"]."/".$voiceoneWSDirName."/utility/provisioning/firmware/data/".$firmware."\n";
      echo "</pre>\n";
      echo "</HTML>";
      printDebug("Firmware has been successfully updated to version ".$arr["name"]." for extension ".$arr["extension"],false);
    }else printDebug("ERROR (mysql is unable to retrireve firmware)",true);
  }else printDebug("ERROR (mysql is unable to retrireve firmware)",true);
  
  function printDebug($text,$die){
  	global $debug,$mac;
    if($debug===true) error_log("[FIRM]Request for mac ".$mac.": ".$text);
  	if($die===true) die("[FIRM]Request for mac ".$mac.": ".$text);
  }
?>